package com.myproject.async;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.*;
public class AsyncHttpExample {
    public static void main(String[] args) throws Exception {
        List<Future<String>> futures = new ArrayList<>();

        ExecutorService executor = Executors.newFixedThreadPool(10);

        List<String> urls = new ArrayList<>();
        urls.add("https://www.example.com/api1");
        urls.add("https://www.example.com/api2");
        urls.add("https://www.example.com/api3");
        urls.add("https://www.example.com/api3");
        urls.add("https://www.example.com/api3");
        urls.add("https://www.example.com/api3");
        urls.add("https://www.example.com/api3");
        urls.add("https://www.example.com/api3");
        urls.add("https://www.example.com/api3");
        urls.add("https://www.example.com/api3");
        urls.add("https://www.example.com/api3");
        urls.add("https://www.example.com/api3");
        urls.add("https://www.example.com/api3");
        urls.add("https://www.example.com/api3");
        urls.add("https://www.example.com/api3");
        urls.add("https://www.example.com/api3");
        urls.add("https://www.example.com/api3");
        urls.add("https://www.example.com/api3");
        urls.add("https://www.example.com/api3");
        urls.add("https://www.example.com/api3");
        urls.add("https://www.example.com/api3");
        urls.add("https://www.example.com/api3");
        urls.add("https://www.example.com/api3");
        urls.add("https://www.example.com/api3");
        urls.add("https://www.example.com/api3");
        urls.add("https://www.example.com/api3");
        urls.add("https://www.example.com/api3");
        urls.add("https://www.example.com/api3");
        urls.add("https://www.example.com/api3");
        urls.add("https://www.example.com/api3");
        urls.add("https://www.example.com/api3");
        urls.add("https://www.example.com/api3");
        urls.add("https://www.example.com/api3");
        urls.add("https://www.example.com/api3");
        urls.add("https://www.example.com/api3");
        urls.add("https://www.example.com/api3");
        urls.add("https://www.example.com/api3");
        urls.add("https://www.example.com/api3");
        urls.add("https://www.example.com/api3");
        urls.add("https://www.example.com/api3");
        urls.add("https://www.example.com/api3");
        urls.add("https://www.example.com/api3");
        urls.add("https://www.example.com/api3");
        urls.add("https://www.example.com/api3");
        urls.add("https://www.example.com/api3");
        urls.add("https://www.example.com/api3");
        urls.add("https://www.example.com/api3");
        urls.add("https://www.example.com/api3");
        urls.add("https://www.example.com/api3");
        urls.add("https://www.example.com/api3");
        urls.add("https://www.example.com/api3");
        urls.add("https://www.example.com/api3");
        urls.add("https://www.example.com/api3");
        urls.add("https://www.example.com/api3");
        urls.add("https://www.example.com/api3");
        urls.add("https://www.example.com/api3");
        urls.add("https://www.example.com/api3");
        urls.add("https://www.example.com/api3");
        for (String url : urls) {
            Callable<String> task = () -> {
                return performRequest(url);
            };

            Future<String> future = executor.submit(task);
            futures.add(future);
        }

        executor.shutdown();

        for (Future<String> future : futures) {
            try {
                String result = future.get();
                System.out.println("Received response: " + result);
            } catch (InterruptedException | ExecutionException e) {
                e.printStackTrace();
            }
        }
    }

    private static String performRequest(String url) throws InterruptedException {
        return "success"+ Thread.currentThread().getName();
    }
}